9 typedef unsigned long long int lluint
;
10 typedef vector
<int> vint
;
12 #define forsn(i, s, n) for (int i = (s); i < (n); i++)
13 #define forn(i, n) forsn (i, 0, n)
17 void pkmp(const string
& s
, vint
& f
) {
19 forsn (i
, 1, s
.size() + 1) {
20 while (z
!= -1 && s
[i
- 1] != s
[z
]) z
= f
[z
];
21 f
[i
] = ++z
; // z might be -1
32 #define buf_sync() { \
33 cin.getline(buf, TAMBUF + 1); \
35 buf_size = cin.gcount(); \
39 #define buf_start() { \
46 void kmp(const string
& s
, vint
& f
) {
48 const int final
= s
.size();
53 cout
<< (pos
+ i
- final
) << " ";
55 while (s
[state
] != buf
[i
]) {
57 if (state
== -1) break;
61 if (buf_size
< TAMBUF
) break;
73 assert(needle_size
== needle
.size());
76 vint
f(needle
.size() + 1);